//
//  HXCycleCCell.m
//  ZCooking
//
//  Created by 韩旭 on 16/9/3.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "HXCycleCCell.h"
#import "HXCycleImageCell.h"
#import "HX_Macro.h"
#import "HXScrollBannerModel.h"

@implementation HXCycleCCell
- (void)setArrCycleSource:(NSMutableArray *)arrCycleSource {
    _arrCycleSource = arrCycleSource;
    [_collectionView reloadData];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatCollectionView];
    }
    return self;
}

- (void)creatCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = 1;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:_collectionView];
    [_collectionView registerNib:[UINib nibWithNibName:@"HXCycleImageCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"reuseCycleImage"];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _arrCycleSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HXCycleImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseCycleImage" forIndexPath:indexPath];
    HXScrollBannerModel *model = self.arrCycleSource[indexPath.row];
    [cell.cycleImage sd_setImageWithURL:[NSURL URLWithString:model.bannerPicture]];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(self.collectionView.HX_width / 2.2, self.contentView.frame.size.height);
}

@end
